package com.qf.mapper;

import com.qf.vo.CategorySellAmts;
import com.qf.vo.DayStatis;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;


public interface StatMapper {
	
    /**
     * 日期范围是30天
     * 日期最近30天的   用户数量（按天统计） 及对应的 日期
     * @param statisDayRange
     * @return
     */
    @Select("select \n" +
            "  DATE_FORMAT(t.add_time,'%Y-%m-%d') dayStr ,\n" +
            "\tcount(1) cnts\n" +
            "from dts_user t\n" +
            "where t.add_time > DATE_ADD(now(),INTERVAL -#{statisDayRange} day)\n" +
            "group by DATE_FORMAT(t.add_time,'%Y-%m-%d')")
    List<DayStatis> findDayStatis(@Param("statisDayRange") int statisDayRange);


//    @Select("select   date_format(t.add_time, '%Y-%m-%d') as `dayStr`,count(1) as `cnts`\n" +
//            "from dts_user t\n" +
//            "where t.add_time > date_sub(now(), interval #{days} day) and t.deleted = 0\n" +
//            "group by date_format(t.add_time, '%Y-%m-%d');")
@Select("select count(8) cnts , DATE_FORMAT(add_time,'%Y-%m-%d') dayStr\n" +
        "from dts_user\n" +
        "where add_time > DATE_ADD(now(),INTERVAL -#{days} day)\n" +
        "group by dayStr")
    List<DayStatis> userDayStatistic(@Param("days") int statisDaysRang);


    @Select("select\n" +
            "    date_format(g.add_time, '%Y-%m-%d') as dayStr, count(1) as cnts,sum(g.order_price) as amts from dts_order g\n" +
            "where g.add_time > date_sub(now(), interval #{days} day) and g.deleted = 0 and g.order_status not in(101.102,103)\n" +
            "group by date_format(g.add_time, '%Y-%m-%d');")
    List<DayStatis> orderDayStatistic(@Param("days") int statisDaysRang);
    
    /**
	 * 类目销售额统计
	 * @return
	 */
    @Select("SELECT\n" +
            "\tdc.`name`,\n" +
            "\tsum( og.price ) AS `value`\n" +
            "FROM\n" +
            "\tdts_order_goods og\n" +
            "\tINNER JOIN dts_goods dg ON og.goods_id = dg.id\n" +
            "\tINNER JOIN dts_category dc ON dg.category_id = dc.id \n" +
            "GROUP BY\n" +
            "\tdg.category_id")
    List<CategorySellAmts> categorySell();
}